package cst.neu.yuejian_31.fragment;


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.List;

import cst.neu.yuejian_31.R;
import cst.neu.yuejian_31.activity.ClubDetailActivity;
import cst.neu.yuejian_31.activity.MainActivity;
import cst.neu.yuejian_31.adapter.PopularityAdapter;
import cst.neu.yuejian_31.bean.ClubBean;
import cst.neu.yuejian_31.iface.PopularityListener;
import cst.neu.yuejian_31.model.PopularityModel;

/**
 * A simple {@link Fragment} subclass.
 */
public class PopularityFragment extends BaseFragment{
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private PopularityAdapter popularityAdapter;
    private List<ClubBean> list=null;
    private View view=null;
    private Context context;
    private TextView clubname;


    PopularityListener popularityListener=new PopularityListener() {
        @Override
        public void onResponse(List<ClubBean> listbean) {
            list=listbean;
            popularityAdapter.setList(list);
        }

        @Override
        public void onFail(String msg) {

            Toast.makeText(context,msg, Toast.LENGTH_SHORT).show();
        }
    };





    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view= inflater.inflate(R.layout.fragment_popularity, container, false);
        PopularityModel popularityModel=new PopularityModel();
        popularityModel.getClubList(popularityListener);
        init();
        return view;

    }


    private void init() {
       context=this.getActivity();
        recyclerView= (RecyclerView) view.findViewById(R.id.recyclerView_popularity);
        layoutManager=new LinearLayoutManager(context);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setHasFixedSize(true);
        popularityAdapter=new PopularityAdapter(context);
        recyclerView.setAdapter(popularityAdapter);
// 设置Item之间间隔样式
        recyclerView .addItemDecoration(new DividerItemDecoration(context,LinearLayoutManager.VERTICAL));

    }


}
